using System;
using System.Drawing;

namespace Web
{
    public static class ColorHelper
    {
        /// <summary>
        ///  Converts a color string to a hex value string ("Green" -> "#000800")
        /// </summary>
        public static string ColorToHexString(string color)
        {
            if (color[0] == '#')
            {
                return color;
            }

            Color c = ColorTranslator.FromHtml(color);
            return ColorToHexString(c);
        }

        /// <summary>
        ///  Converts a Color to a hex value string (Color.Green -> "#000800")
        /// </summary>
        public static string ColorToHexString(Color c)
        {
            string r = Convert.ToString(c.R, 16);
            if (r.Length < 2)
                r = "0" + r;
            string g = Convert.ToString(c.G, 16);
            if (g.Length < 2)
                g = "0" + g;
            string b = Convert.ToString(c.B, 16);
            if (b.Length < 2)
                b = "0" + b;

            return r + g + b;
        }
    }
}